package com.kckj.comm.validation;

import java.util.regex.Pattern;

/**
 * @author hang
 * @date 2020-08-18-10:43
 * @description 摄像头验证类
 */
public class IpValidation extends AbstractValidationCell {

    @Override
    public void validateCell(int row, Object cellValue) throws Exception {
        String cell = cellValue.toString();
        String ipReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
                + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
                + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
                + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
        Pattern ipPattern = Pattern.compile(ipReg);

        boolean flag = ipPattern.matcher(cell).matches();
        if (!flag) {
            throw new Exception("excel数据行第" + row + "行校验IP地址错误!");
        }
    }

}
